//
//  UIKitLayer.m
//  ShoutBoss
//
//  Created by Yin supmarboro on 09-6-26.
//  Copyright 2009 JW. All rights reserved.
//

#import "UIKitLayer.h"


@implementation UIKitLayer
-(id) init
{
	self = [super init];
	pView = [[UIView alloc]initWithFrame : CGRectMake(0,0,1,1)];
	[pView setBackgroundColor: [UIColor clearColor]];
	[pView setCenter: ccp(0,0)];
	
	[super setPosition: ccp(0,0)]; 
	
	[[[Director sharedDirector] openGLView]  addSubview:pView]; 
	
	NSLog(@"pView inserted");
	return self;
} 

-(void) dealloc
{ 
	
	if(pView)
	{
		NSLog(@"pView deallocing");
		[pView removeFromSuperview];
		[pView release];
	}
	[super dealloc];
} 

-(void) addChild : (UIView *) subView
{
	NSAssert(pView,@"subView must be valid");
	[pView addSubview: subView];
} 

-(id) addChild: (CocosNode*)node z:(int)z
{
	NSAssert(false,@"This function is not allowed!");
	return nil;
} 

-(id) addChild: (CocosNode*)node z:(int)z tag:(int)tag
{
	NSAssert(false,@"This function is not allowed!");
	return nil;
} 

-(id) addChild: (CocosNode*)node z:(int)z parallaxRatio:(CGPoint)c
{
	NSAssert(false,@"This function is not allowed!");
	return nil;
} 

-(void) insertChild:(CocosNode*) child z:(int)z
{
	NSAssert(false,@"This function is not allowed!");
} 

-(void) reorderChild:(CocosNode*) child z:(int)z
{
	NSAssert(false,@"This function is not allowed!");
} 

-(void) setVisible : (bool) agv
{
	super.visible = agv;
	pView.hidden = !agv;
} 

-(void) setPosition : (CGPoint) point
{
	[super setPosition: point];
	[pView setCenter: point];
} 

-(void) setFrame : (CGRect) frame
{
	[pView setFrame: frame];
} 

-(void) setBackgroundColor : (UIColor *)color
{
	[pView setBackgroundColor: color];
} 

@end